$(document).ready(function() {

    var base_url = $('body').data('baseurl');

    $('.carousel').carousel({
        interval: 2000
    })
    
	// Post Report Incorrect
	$("#post_review").on('submit', function() {

		// ajax post method to pass form data to the
		var revimg = base_url + "/public/ajax-loader2.gif";
		$('#rev_message').html('<img src="' + revimg + '" />');
	//	$('#rev_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"post_id" : $('#post_id').val(),
			"rev_name" : $('#rev_name').val(),
			"rev_email" : $('#rev_email').val(),
			"rev_contact" : $('#rev_contact').val(),
			"selectbox-mylocation2" : $('#selectbox-mylocation2').val(),
			"rev_ratting" : $('#rev_ratting').val(),
			"rev_comment" : $('#rev_comment').val()
			
		//	"selectbox-mylocation3" : $('#selectbox-mylocation3').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#rev_message').html('');
				$("#rev_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
				$('#post_rev').attr('disabled', 'disabled');

				$('#rev_message').html('');
				$("#rev_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				$("#form-block").hide();
			}
		}, 'json');
		return false
	});




	
	// Post Report Incorrect
	$("#post_incorrect").on('submit', function() {

		// ajax post method to pass form data to the
		var incimg = base_url + "/public/ajax-loader2.gif";
		$('#report_message').html('<img src="' + incimg + '" />');
		//$('#report_message').html('Please wait...');
		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"post_id" : $('#post_id').val(),
			"report_name" : $('#report_name').val(),
			"report_email" : $('#report_email').val(),
			"selectbox-mylocation3" : $('#selectbox-mylocation3').val(),
			"listing_url1" : $('#listing_url1').val(),
			"report_contact" : $('#report_contact').val(),
			"report_type" : $('#report_type').val(),
			"report_description" : $('#report_description').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#report_message').html('');
				$("#report_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
				$('#post_report').attr('disabled', 'disabled');

				$('#report_message').html('');
				$("#report_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				$("#form-block").hide();
			}
		}, 'json');
		return false
	});




	
	// Post Report Incorrect
	$("#post_enquiry").on('submit', function() {

		// ajax post method to pass form data to the

		var img = base_url + "/public/ajax-loader2.gif";
		$('#enquiry_message').html('<img src="' + img + '" />');
	//	$('#enquiry_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"post_id" : $('#post_id').val(),
			"enquiry_name" : $('#enquiry_name').val(),
			"enquiry_email" : $('#enquiry_email').val(),
			"selectbox-mylocation1" : $('#selectbox-mylocation1').val(),
			"owner_email" : $('#owner_email').val(),
			"listing_url" : $('#listing_url').val(),
			"enquiry_contact" : $('#enquiry_contact').val(),
			"enquiry_description" : $('#enquiry_description').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#enquiry_message').html('');
				$("#enquiry_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
				$('#post_enq').attr('disabled', 'disabled');

				$('#enquiry_message').html('');
				$("#enquiry_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				$("#form-block").hide();
			}
		}, 'json');
		return false
	});





	// Post Report Incorrect
	$("#post_claim").on('submit', function() {

		// ajax post method to pass form data to the

		var claimimg = base_url + "/public/ajax-loader2.gif";
		$('#claim_message').html('<img src="' + claimimg + '" />');
	//	$('#claim_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"post_id" : $('#post_id').val(),
			"claim_name" : $('#claim_name').val(),
			"claim_email" : $('#claim_email').val(),
			"selectbox-mylocation4" : $('#selectbox-mylocation4').val(),
			"listing_url2" : $('#listing_url2').val(),
			"claim_position_at" : $('#claim_position_at').val(),
			"claim_contact" : $('#claim_contact').val(),
			"claim_description" : $('#claim_description').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#claim_message').html('');
				$("#claim_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
				$('#post_clm').attr('disabled', 'disabled');

				$('#claim_message').html('');
				$("#claim_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				$("#form-block").hide();
			}
		}, 'json');
		return false
	});


	
	
	
	// Post Requirement
	$("#post_requirement").on('submit', function() {

		// ajax post method to pass form data to the

		var requirement = base_url + "/public/ajax-loader2.gif";
		$('#requirement').html('<img src="' + requirement + '" />');
	//	$('#claim_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"selectbox-1" : $('#selectbox-1').val(),
			"requirement_details" : $('#requirement_details').val(),
			"selectbox-mylocation5" : $('#selectbox-mylocation5').val(),
			"requirement_name" : $('#requirement_name').val(),
			"requirement_email" : $('#requirement_email').val(),
			"requirement_contact" : $('#requirement_contact').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#requirement').html('');
				$("#requirement").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
			//	$('#post_clm').attr('disabled', 'disabled');

				$('#requirement').html('');
				$("#requirement").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				//$("#form-block").hide();
			}
		}, 'json');
		return false
	});


	
	// Post Requirement
	$("#post_lead").on('submit', function() {

		// ajax post method to pass form data to the

		var lead_message = base_url + "/public/ajax-loader2.gif";
		$('#lead_message').html('<img src="' + lead_message + '" />');
	//	$('#claim_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"req_category" : $('#req_category').val(),
			"req_email" : $('#req_email').val(),
			"lead_name" : $('#lead_name').val(),
			"lead_email" : $('#lead_email').val(),
			"lead_description" : $('#lead_description').val(),
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#lead_message').html('');
				$("#lead_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
			//	$('#post_clm').attr('disabled', 'disabled');

				$('#lead_message').html('');
				$("#lead_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				//$("#form-block").hide();
			}
		}, 'json');
		return false
	});

	
	
	// Post Products Enquiry
	$("#post_proenq").on('submit', function() {

		// ajax post method to pass form data to the

		var proenq_message = base_url + "/public/ajax-loader2.gif";
		$('#proenq_message').html('<img src="' + proenq_message + '" />');
	//	$('#claim_message').html('Please wait...');

		$.post($(this).prop('action'), {
			// "csrf_token": $( this ).find( 'input[name=csrf_token]' ).val(),
			"pro_enq_name" : $('#pro_enq_name').val(),
			"product_id" : $('#product_id').val(),
			"company_email" : $('#company_email').val(),
			"product_url" : $('#product_url').val(),
			"pro_enq_email" : $('#pro_enq_email').val(),
			"pro_enq_contactno" : $('#pro_enq_contactno').val(),
			"selectbox-mylocation7" : $('#selectbox-mylocation7').val(),
			"pro_enq_description" : $('#pro_enq_description').val()
		}, function(data) {
			// response after the process.
			var status = data.status;
			// alert(status);
			if (status == 'Fail') {
				$('#proenq_message').html('');
				$("#proenq_message").html(data.message).fadeIn('slow');
			} else {
				// $('input[type="submit"]').attr('disabled', 'disabled');
				$('#pro_enq').attr('disabled', 'disabled');

				$('#proenq_message').html('');
				$("#proenq_message").html(data.message).fadeIn('slow');
				// $('#post_enquiry')[0].reset();
				//$("#form-block").hide();
			}
		}, 'json');
		return false
	});
	
	
	
//--CLEAR LOCATION
$("#clear_location").on( 'click', function() {
    $p = base_url + '/location/clear';
    $.ajax({
        url : $p,
        success : function(response) {// response is value returned from
            $u = response;
            //         alert($u);
            //document.location.reload();
            window.location.href = $u;
        }
    });
});
//--END OF CLEAR LOCATION

//--BANNER CLICK--//
$(".clicked").on( 'click', function() {
    $bannerID = $(this).attr("banner-id");
    //alert ($bannerID);
    $p = base_url + '/banner/clicked/'+$bannerID;
    $.ajax({
        url : $p,
        success : function(response) {// response is value returned from
            $u = response;
            if($u){
                //window.location.href = $u;
                window.open(
                    $u,
                    '_blank' // <- This is what makes it open in a new window.
                );
                return false;
            }
        }
    });
});
});